package cn.example.thread;

/**
 * @author July
 * @description
 * @create 2025-09-01 14:36
 */
public class CycleWait implements Runnable {
    private String value;

    @Override
    public void run() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        value = "we have data now";
    }

    public static void main(String[] args) throws InterruptedException {
        CycleWait cw = new CycleWait();
        Thread t = new Thread(cw);
        t.start();
        // 主线程等待法
//        while (cw.value == null) {
//            Thread.currentThread().sleep(100);
//        }

        // 使用join方法
        t.join();
        System.out.println("value: " + cw.value);
    }
}
